home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 1996 May / Software of the Month Club 1996 May.iso / mac / ISO9660 / OS2 / MESA / EXAMPLES / SRC / FEED / FEED.CPP next >
Encoding:
C/C++ Source or Header  |  1995-09-21  |  2.8 KB  |  100 lines  |  [TEXT/hscd]

  1. #define INCL_WIN
  2. #define INCL_GPI
  3. #define INCL_DOS
  4. #define M2Z
  5.  
  6. #include <os2.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <math.h>
  11. #include <bseerr.h>
  12. #include "feed.h"
  13.  
  14. void contFeed(void)
  15. {
  16.     // supports the 2.0, 2.0.1, and 2.0.2 demo sheets
  17.     #define OLDNUM 11
  18.     static char *oldnames[OLDNUM] = {"HOPII","STONE","MESAC",
  19.         "CARGZ","ARCSD","SNTFE","FLAGS",
  20.         "PHNIX","ALBQU","CACTS","TBLWD"};
  21.     static double oldvalues[OLDNUM] = {75,35,17,30,13,37,16,9,19,62,24};
  22.  
  23.  
  24.     #define NUM 6
  25.     static char *names[NUM] = {"DM","RAND","FRANC","POUND","PESATA","ESCUDO"};
  26.     static double values[NUM] = {1.55,3.6,5.1,0.62,125.0,150.0};
  27.     static double values2[NUM] = {1.55,3.6,5.1,0.62,125.0,150.0};
  28.     static double ranges[NUM * 2] = {1.63,1.47,4.1,3.3,5.5,4.85,0.7,0.57,
  29.                                         137.00,115.00,183.00,135.00};
  30.     int x;
  31.  
  32.     for (;;) {
  33.         int t;
  34.         double d;
  35.         double rng;
  36.  
  37.         for (x = 0; x < OLDNUM; x++)
  38.         {
  39.             setRTFValue("BID",oldnames[x],oldvalues[x]);
  40.             d = rand();
  41.             d /= 32767;
  42.             d -= 0.5;
  43.             d /= 50;
  44.             d += 1;
  45.             oldvalues[x] *= d;
  46.             oldvalues[x] *= 100;
  47.             t = oldvalues[x];
  48.             oldvalues[x] = t;
  49.             oldvalues[x] /= 100;
  50.         }
  51.  
  52.         for (x = 0; x < NUM; x++)
  53.         {
  54.             setRTFValue(names[x],"CURRENT",values[x]);
  55.             setRTFValue(names[x],"+30",values2[x]);
  56.  
  57.             rng = (ranges[x * 2] - ranges[x * 2 + 1]);
  58.  
  59.             t = rand() % 100;
  60.             t -= 50;
  61.             d = t;
  62.             d = rng * d/1000;
  63.             d += values[x];
  64.             if (d > ranges[x * 2]) {
  65.                 d = ranges[x * 2];
  66.             } else if ( d < ranges[x * 2 +1]) {
  67.                 d = ranges[x * 2 +1];
  68.             } // endif
  69.             values[x] = d;
  70.  
  71.             t = rand() % 100;
  72.             t -= 50;
  73.             d = t;
  74.             d = rng * d/1000;
  75.             d += values2[x];
  76.             if (d > ranges[x * 2]) {
  77.                 d = ranges[x * 2];
  78.             } else if ( d < ranges[x * 2 +1]) {
  79.                 d = ranges[x * 2 +1];
  80.             } // endif
  81.             values2[x] = d;
  82.         }
  83.  
  84.         DosSleep(200);
  85.     }
  86. }
  87.  
  88. main(int argc,char **argv)
  89. {
  90.  
  91.     if (argc == 4) {
  92.         setRTFValue(argv[1],argv[2],atof(argv[3]));
  93.     }
  94.     else if (argc == 2 && !strcmp(argv[1],"-t")) contFeed();
  95.  
  96.     else printf("To send a single value to the Mesa Real Time System, type \"FEED key1 key2 value\"\nwhere key1 & 2 are strings denoting the keys used to look up the values\nvalue is a number which contains the value to set.\nTo run the feed program continuously, type \"FEED -t\" at the command prompt\n");
  97.  
  98.     return 0;
  99. }
  100.